<template>
  <div class="data-management">
    <header style="margin-left: 50px; font-size: 17px">
      <h1>数据管理</h1>
    </header>
    <div class="search-container">
      <input
        v-model="searchParams.tableName"
        placeholder="输入您的数据表"
        style="margin-left: 2.6%"
      />
      <button @click="fetchTables">搜索</button>
    </div>
    <div class="table-container">
      <TableComponent />
    </div>
    <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
  </div>
</template>

<script>
import axios from "axios";
import TableComponent from "@/components/TableComponent.vue";

export default {
  name: "ManagementPage",
  components: {
    TableComponent,
  },
  data() {
    return {
      tables: [],
      searchParams: {
        tableName: "",
        columnName: "",
      },
      errorMessage: "",
    };
  },
  methods: {
    async fetchTables() {
      try {
        const response = await axios.get("/api/tables", {
          params: this.searchParams,
        });
        this.tables = response.data.tables;
      } catch (error) {
        this.errorMessage = "无法获取数据表列表";
        console.error(error);
      }
    },
    handleButtonClick() {
      // Button click handler
      console.log("Button clicked");
    },
  },
};
</script>

<style scoped>
.data-management {
  background-color: #fff;
  padding: 20px;
  padding-top: 40px;
  height: 89vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  margin-top: 50px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
}

.search-container {
  display: flex;
  align-items: center;
  justify-content: left;
  margin: 20px 0;
}

.search-container input {
  padding: 10px 15px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 5px 0 0 5px;
  width: 20%;

  transition: border-color 0.3s;
}

.search-container input:focus {
  border-color: #007bff;
  outline: none;
}

.search-container button {
  padding: 10px 15px;
  font-size: 16px;
  cursor: pointer;
  border: 1px solid #ccc;
  background-color: #007bff;
  color: #fff;
  border-radius: 0 5px 5px 0;
  transition:
    background-color 0.3s,
    box-shadow 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.search-container button:hover {
  background-color: #0056b3;
}

.search-container button:active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.search-container input,
.search-container button {
  border: 1px solid #00000010;
}

.table-container {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0px; /* 确保没有左右间距 */
  margin: 0px; /* 确保没有左右间距 */
}

.table-container > div {
  width: 95%;
  height: 100%;
}
.error {
  color: red;
}
</style>
